package com.yqzl.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yqzl.entity.Blog;
import com.yqzl.mapper.T_BlogMapper;
import com.yqzl.service.T_BlogService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class T_BlogServiceImpl extends ServiceImpl<T_BlogMapper, Blog> implements T_BlogService {
  //  ServiceImpl<T_BlogMapper, Blog> 是 MyBatis- Plus 提供的一个通用实现类。
//  它内部已经自动注入了 T_BlogMapper，并提供了一个名为 baseMapper 的字段供您使用。 不用再次注入
  @Override
  public Blog getBlogByBid(String bid) {
    QueryWrapper<Blog> blogQueryWrapper = new QueryWrapper<>();
    blogQueryWrapper.eq("bid", bid);
    Blog blog = baseMapper.selectOne(blogQueryWrapper);
    return blog;
  }

  //   根据 用户返回所有的博客
  @Override
  public List<Blog> getBlogByUid(String uid) {
    QueryWrapper<Blog> blogQueryWrapper = new QueryWrapper<>();
    blogQueryWrapper.eq("uid_author", uid);
    List<Blog> blogs = baseMapper.selectList(blogQueryWrapper);
    return blogs;
  }

  @Override
  public void delBlogByBid(String bid) {
    QueryWrapper<Blog> blogQueryWrapper = new QueryWrapper<>();
    blogQueryWrapper.eq("bid", bid);
    baseMapper.delete(blogQueryWrapper);
  }

  @Override
  public void upBlogByBid(Blog blog) {
    QueryWrapper<Blog> blogQueryWrapper = new QueryWrapper<>();
    blogQueryWrapper.eq("bid", blog.getBid());
    baseMapper.update(blog, blogQueryWrapper);
  }


}
